var path = require('path')
var webpack = require('webpack')
var ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
    entry: './src/main.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        // publicPath: 'Content/stage/node_modules/',
        filename: 'build.js'
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                options: {
                    loaders: {}
                    // other vue-loader options go here
                }
            }, {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            }, {
                test: /\.css$/,
                 loader:  ExtractTextPlugin.extract({fallback:"style-loader",use:"css-loader"})
            }, {
                test: /\.(png|jpg|gif|svg|mp4)$/,
                loader: 'file-loader',
                options: {
                    name: '[name].[ext]?[hash]'
                }
            }, {
                test: /\.(eot|woff|woff2|svg|ttf)([\?]?.*)$/,
                loader: "file-loader",
                // query: {
                //     name: 'element-ui/packages/theme-default/src/fonts/[name].[ext]'
                // }
            }, {
                // 得到jquery模块的绝对路径
                test: require.resolve('jquery'),
                // 将jquery绑定为window.jQuery 和 window.$
                loader: 'expose-loader?jQuery!expose-loader?$'
            }
        ]
    },
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.common.js'
        }
    },
    devServer: {
        //host: '192.168.198.185',
        historyApiFallback: true,
        noInfo: true,
        //配置代理，使得允许跨域
        proxy: {
            '/': {
                // target: 'http://192.168.198.185:60861/Content/stage/node_modules/', //代理服务端口
                target: 'http://localhost:60861/Content/stage/node_modules/',
                secure: false
            }
        }
    },
    performance: {
        hints: false
    },
    devtool: '#eval-source-map',
    plugins: [new ExtractTextPlugin("styles.css")]
}

if (process.env.NODE_ENV === 'production') {
    module.exports.devtool = '#source-map'
    // http://vue-loader.vuejs.org/en/workflow/production.html
    module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"production"'
            }
        }),
        new webpack
            .optimize
            .UglifyJsPlugin({
                sourceMap: true,
                compress: {
                    warnings: false
                }
            }),
        new webpack.LoaderOptionsPlugin({minimize: true})
    ])
}